<?php include COMMON_PATH.'/header.html'; ?>
<div class="page page_store">
  <div class="weui-header">
    <img src="<?=$dataOne['store']['logoImg']?>" class="logo">
    <p class="name"><?=$dataOne['store']['storesName']?></p>
    <div class="label-wrapper">
      <?php if($dataOne['identity_detail']['shop_type'] == 2 ):?>
      <span class="label-qj">旗舰店</span>
      <?php elseif($dataOne['identity_detail']['shop_type'] == 1 ):?>
      <span class="label-zy">专营店</span>
      <?php elseif($dataOne['identity_detail']['shop_type'] == 3 ):?>
      <span class="label-norz">未认证</span>
      <?php endif;?>


      <?php if($dataOne['identity_detail']['identity'] == 1 ):?>
      <!-- <span class="label-personal"></span> -->
      <?php elseif($dataOne['identity_detail']['identity'] == 2 ):?>
      <!-- <span class="label-enterprise"></span> -->

      <?php endif;?>
    </div>
    <p class="realname"><?=$dataOne['store']['company_name_convert']?></p>
    <?php if($dataOne['is_my_store'] == 0):?>
    <!--非自己的店铺才有关注-->
    <?php if($dataOne['has_follow']):?>
    <button type="button" class="follow-btn"><span class="icon-like islike"></span>已关注</button>
    <?php else:?>
    <button type="button" class="follow-btn" id="follow"><span class="icon-like"></span>关注</button>
    <?php endif;?>
    <?php endif;?>
  </div>
  <div class="weui-body">
    <ul class="store-detail-tab">
      <li class="item curr" data-index="0"><span>店铺资料</span></li>
      <li class="item" data-index="1"><span>现货商品</span></li>
      <li class="item" data-index="2"><span>供应信息</span></li>
    </ul>
    <div class="store-detail-item">
      <div class="detail-item">
        <div class="el-scroll">
          <div class="swiper-container swiper-scroll" id="infoScroll">
            <div class="swiper-wrapper">
              <div class="swiper-slide">
                <div class="wrapper">
                  <h3 class="title">主营业务</h3>
                  <div class="wich-content"><?=$dataOne['store']['mainBuiness']?></div>
                </div>
                <div class="wrapper">
                  <h3 class="title">店铺简介</h3>
                  <div class="wich-content"><?=$dataOne['store']['detail']?></div>
                </div>
                <div class="weui-cells">
                  <h3 class="title2">联系方式</h3>
                  <?php if($dataOne['userInfo']['yst_user_type'] == 1):?>
                  <!--个人-->
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>联系人</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['userInfo']['real_name_convert']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>手机号码</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['userInfo']['mobile_phone_convert']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>经营地址</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['store']['all_address']?></p>
                    </div>
                  </div>

                  <?php elseif($dataOne['userInfo']['yst_user_type'] == 2):?>
                  <!--企业-->
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>联系人</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['enterprise']['agent_convert']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>手机号码</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['enterprise']['phone_convert']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>经营地址</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['store']['all_address']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>公司电话</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['enterprise']['company_phone_convert']?></p>
                    </div>
                  </div>
                  <div class="weui-cell">
                    <div class="weui-cell__bd">
                      <p>公司地址</p>
                    </div>
                    <div class="weui-cell__ft">
                      <p><?=$dataOne['enterprise']['all_address']?></p>
                    </div>
                  </div>
                  <?php endif;?>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="detail-item" style="display: none;">
        <div class="el-scroll">
          <div class="swiper-container" id="productScroll">
            <div class="swiper-wrapper">
              <div class="swiper-slide">
                <ul class="store-recomend-list" id="productList">
                </ul>
              </div>
              <div class="load-more-wrapper">
                <img src="/res/mobile/images/loading.gif" class="load-more-pic">
                <p class="load-more-text">下拉加载更多</p>
              </div>
            </div>
          </div>
          <div class="no-data" style="display: none;">
            <img src="/res/mobile/images/data_pic.png" class="pic">
            <p class="tips">暂时没有商品信息</p>
          </div>
        </div>
      </div>
      <div class="detail-item" style="display: none;">
        <div class="el-scroll">
          <div class="swiper-container" id="supplyScroll">
            <div class="swiper-wrapper">
              <div class="swiper-slide">
                <ul class="store-supply-list" id="supplyList">
                </ul>
              </div>
              <div class="load-more-wrapper">
                <img src="/res/mobile/images/loading.gif" class="load-more-pic">
                <p class="load-more-text">下拉加载更多</p>
              </div>
            </div>
            <div class="no-data" style="display: none;">
              <img src="/res/mobile/images/data_pic.png" class="pic">
              <p class="tips">暂时没有商品信息</p>
            </div>
          </div>
          <div class="no-data" style="display: none;">
            <img src="/res/mobile/images/data_pic.png" class="pic">
            <p class="tips">暂时没有供应订单</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<?php include COMMON_PATH.'/footer.html'; ?>
<script>
  $(function () {
    var supply_data = {
      page: 1,
      limit: 10,
      store_id: mobileCommon.getQueryString('id')
    },
      product_data = {
        page: 1,
        limit: 10,
        store_id: mobileCommon.getQueryString('id')
      },
      isflag = false, //防止多次获取数据
      scroll = {
        infoScroll: null,
        productScroll: null,
        supplyScroll: null
      }

    //切换窗
    $('.store-detail-tab').on('click', 'li', function () {
      $(this).addClass('curr').siblings().removeClass('curr');
      var index = $(this).data('index');
      $('.store-detail-item').find('.detail-item').eq(index).show().siblings('.detail-item').hide();
      $('.detail-item').eq(index).find('.swiper-container').addClass('swiper-scroll');
      setTimeout(() => {
        scroll.infoScroll.update();
        scroll.productScroll.update();
        scroll.supplyScroll.update();
      }, 100);
    })
    //关注店铺
    $('#follow').on('click', function () {
      var $this = $(this);
      var loading = weui.loading();
      $.ajax({
        url: '/mobile/store/addFollow',
        dataType: 'json',
        type: 'POST',
        data: {
          storeId: mobileCommon.getQueryString('id')
        },
        success: function (res) {
          if (res.code == 1) {
            weui.toast(res.msg);
            $this.text('已关注');
            $this.find('.icon-like').addClass('islike');
          } else {
            weui.topTips(res.msg);
          }
        },
        complete: function () {
          loading.hide();
        }
      })
    })

    // 资料滑动
    scroll.infoScroll = swiperScroll(function () { }, '#infoScroll')

    function supplyModule() {
      // 获取供应数据
      function getSupply(field) {
        var loading = weui.loading();
        var item_p = 2;
        isflag = true;
        $.ajax({
          url: '/mobile/store/supplyList',
          dataType: 'json',
          type: 'POST',
          data: field,
          success: function (res) {
            if (res.code == 1) {
              if (res.data.total != 0) {
                var str = '',
                  list = res.data.list;
                if (list.length == 0) {
                  weui.toast('没有更多记录了', {
                    duration: 2000,
                    className: 'no-more-data'
                  });
                  return false;
                }
                for (var i = 0; i < list.length; i++) {
                  str += '<li class="item" data-id="' + list[i].id + '">';
                  str += '<div class="item-t">';
                  str += '<div class="info-wrapper">';
                  str += '<h3 class="title">' + list[i].product_name + '<span class="label-type">' + list[i].category_name + '</span></h3>';
                  str += '<p class="desc">' + list[i].specs + '</p>';
                  str += '<p class="price"><span class="count">' + list[i].price + '</span>/' + list[i].unit_name + '</p>';
                  str += '</div>';
                  str += '</div>';
                  str += '<div class="item-b">';
                  str += '<div class="time">' + list[i].publish_time + '</div>';
                  str += '<div class="address">' + list[i].city + '</div>';
                  str += '</div>';
                  str += '</li>';
                }
                $('#productList').append(str);
                $('#supplyScroll').show();
                $('#supplyScroll').siblings('.no-data').hide();
                setTimeout(() => {
                  supplyScroll.update();
                }, 100);
              } else {
                $('#supplyScroll').siblings('.no-data').show();
                $('#supplyScroll').hide();
              }
            } else {
              weui.topTips(res.msg)
            }
          },
          complete: function () {
            loading.hide();
            isflag = false;
          }
        })
      }
      getSupply(supply_data);
      // 供应跳转
      $('#supplyList').on('click', 'li', function () {
        // window.location.href = '/mobile/mall/detail?id=' + $(this).data('id');
        console.log('暂无跳转')
      })

      // 供应滑动及加载功能
      scroll.supplyScroll = swiperScroll(function () {
        if (isflag) {
          return false
        }
        supply_data.page++;
        getProduct(product_data);
      }, '#supplyScroll')
    }

    supplyModule();
    // 商品模块
    function productModule() {
      // 获取商品数据
      function getProduct(field) {
        var loading = weui.loading();
        var item_p = 1;
        isflag = true;
        $.ajax({
          url: '/mobile/store/productlist',
          dataType: 'json',
          type: 'POST',
          data: field,
          success: function (res) {
            if (res.code == 1) {
              if (res.data.total != 0) {
                var str = '',
                  list = res.data.list;
                if (list.length == 0) {
                  weui.toast('没有更多记录了', {
                    duration: 2000,
                    className: 'no-more-data'
                  });
                  return false;
                }
                for (var i = 0; i < list.length; i++) {
                  str += '<li class="item" data-id="' + list[i].id + '">';
                  str += '<a href="javascript:;">';
                  str += '<div class="box">';
                  str += '<div class="pic-wrapper">';
                  str += '<img src="' + list[i].img_path + '" class="pic">';
                  str += '</div>';
                  str += '<h3 class="name">' + list[i].product_name + '/' + list[i].place_name + ' ' + list[i].specs + ' ' + list[i].level_name + '</h3>';
                  str += '<div class="label-type-wrapper">';
                  str += '<span class="label-type">' + list[i].category_name + '</span>';
                  str += '</div>';
                  str += '<p class="price">￥<span class="count">' + list[i].price + '</span></p>';
                  str += '</div>';
                  str += '</a>';
                  str += '</li>';
                }
                $('#productList').append(str);
                $('#productScroll').show();
                $('#productScroll').siblings('.no-data').hide();
                setTimeout(() => {
                  productScroll.update();
                }, 100);
              } else {
                $('#productScroll').siblings('.no-data').show();
                $('#productScroll').hide();
              }
            } else {
              weui.topTips(res.msg)
            }
          },
          complete: function () {
            loading.hide();
            isflag = false;
          }
        })
      }
      getProduct(product_data);
      // 商品跳转
      $('#productList').on('click', 'li', function () {
        window.location.href = '/mobile/mall/detail?id=' + $(this).data('id');
      })

      // 现货商品渲染滑动及加载功能
      scroll.productScroll = swiperScroll(function () {
        if (isflag) {
          return false
        }
        product_data.page++;
        getProduct(product_data);
      }, '#productScroll')
    }
    productModule();
  })
</script>